package grape.workflow.rest.canstartprocess.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.workflow.rest.canstartprocess.form.CanStartProcessListForm;
import grape.workflow.service.canstartprocess.query.CanStartProcessListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.workflow.rest.canstartprocess.form.CanStartProcessCreateForm;
import grape.workflow.rest.canstartprocess.form.CanStartProcessUpdateForm;
import grape.workflow.rest.canstartprocess.form.CanStartProcessListPageForm;
import grape.workflow.rest.canstartprocess.vo.CanStartProcessVo;
import grape.workflow.rest.canstartprocess.mapper.CanStartProcessWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.workflow.service.canstartprocess.po.CanStartProcess;
import grape.workflow.service.canstartprocess.api.ICanStartProcessService;
import java.util.List;
/**
 * <p>
 * 可发起的流程 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-06-28
 */
@RestController
@RequestMapping("/workflow/canstartprocess")
@Api(tags = "可发起的流程相关接口")
public class CanStartProcessController extends BaseController<CanStartProcessVo, CanStartProcess> {

    @Autowired
    private CanStartProcessWebMapper currentWebMapper;
    @Autowired
    private ICanStartProcessService currentService;



     @ApiOperation("添加可发起的流程")
     @PreAuthorize("hasAuthority('canstartprocess:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public CanStartProcessVo create(@RequestBody @Valid CanStartProcessCreateForm cf) {
         CanStartProcess po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询可发起的流程")
     @PreAuthorize("hasAuthority('canstartprocess:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public CanStartProcessVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除可发起的流程")
     @PreAuthorize("hasAuthority('canstartprocess:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新可发起的流程")
     @PreAuthorize("hasAuthority('canstartprocess:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public CanStartProcessVo update(@PathVariable String id,@RequestBody @Valid CanStartProcessUpdateForm uf) {
         CanStartProcess po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("不分页查询可发起的流程")
    @PreAuthorize("hasAuthority('canstartprocess:single:list')")
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    public List<CanStartProcessVo> list(CanStartProcessListForm listPageForm) {
        CanStartProcess po = currentWebMapper.formToPo(listPageForm);
        CanStartProcessListQuery canStartProcessListQuery = new CanStartProcessListQuery();
        canStartProcessListQuery.setPoQuery(po);
        return super.list(canStartProcessListQuery);
    }

    @ApiOperation("分页查询可发起的流程")
    @PreAuthorize("hasAuthority('canstartprocess:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<CanStartProcessVo> listPage(CanStartProcessListPageForm listPageForm) {
         CanStartProcess po = currentWebMapper.formToPo(listPageForm);
        CanStartProcessListQuery canStartProcessListQuery = new CanStartProcessListQuery();
        canStartProcessListQuery.setPoQuery(po);
        return super.listPage(canStartProcessListQuery,listPageForm);
     }

}
